//todo 选择退款原因
$(".refundReason").click(function(){
    var me=$(this);
    me.hasClass("animationUp")?me.removeClass("animationUp").addClass("animationDown"):me.removeClass("animationDown").addClass("animationUp")
});

$(".refundReason li").click(function(e){
    e.stopPropagation();
    var text=$(this).children().text();
    $(".refundReason>div>span:nth-child(2)").text(text);
    $(".refundReason input").val(text);
    $(".refundReason").addClass("animationDown").removeClass("animationUp");
});

//todo 添加图片预览删除功能
$(".a-upload").on("change","input",function(){
    var me=this;
    var ul=$(this).parent().parent().parent().parent()[0];
    var files=me.files;
    var existedImgLength=$(ul).find("img").length;
    var totalLength=files.length+existedImgLength;
    if(files.length>3||totalLength>3){
        prompt("最多可选3张图片");
        return;
    }else {
        var startIndex=0;
        if(existedImgLength!=0){
            startIndex=existedImgLength;
        }
        iterator(0);
        function iterator(i){
            if(i==files.length){
                if(totalLength==3){
                    $(ul).find("li.a-upload-box").css("display","none");
                }
                return;
            }
            reader=new FileReader();
            reader.readAsDataURL(me.files[i]);
            reader.onload=function(e){
                $(ul).find("li.a-upload-box").before("<li><img data-index='"+(startIndex+i)+"' src='"+this.result+"'/></li>");
                iterator(i+1);
            };
        }
    }
});
var swiper;
//todo 初始化 图片预览弹框高度
var height=window.screen.availHeight;
$(".coverBox").css("height",height);
$("#previewImg .main").css("height",height);
//todo 评价图片预览
$("ul.pic").on("click","img",function(e){
    e.stopPropagation();
    $("#previewImg .imgs").empty();
    var current_img=$(this).attr("src");//当前点击图片的src
    var current_index=$(this).attr("data-index");
    //$("#previewImg .current").html(current_index);
    // <div class="swiper-slide">Slide 1</div>
    $("#previewImg").show();
    $("#previewImg .imgs").html("<div class='swiper-container'><div class='swiper-wrapper'></div></div>");
    var imgs=$(".pic img");
    $(".total").html(imgs.length);
    $("#previewImg .imgs .swiper-wrapper").css("transform","translate3d(-"+(current_index)*350+"px,0px,0px)");
    for(var i=0;i<imgs.length;i++){
        var src=$(imgs[i]).attr("src");
        //debugger;
        //if((i+1)==current_index){
        //    $("#previewImg .imgs .swiper-wrapper").append("<div class='swiper-slide swiper-slide-active' data-index='"+(i+1)+"'><img src='"+current_img+"' /></div>");
        //}else {
        $("#previewImg .imgs .swiper-wrapper").append("<div class='swiper-slide' data-index='"+(i)+"'><img src='"+src+"' /></div>");
        //}
        if(i==imgs.length-1){
            //$("#previewImg .imgs").hwSlider({
            //    autoPlay: false,
            //    dotShow: true,
            //    touch: true,
            //    start:Number(current_index)
            //});
            swiper = new Swiper('.swiper-container', {
                pagination: '.swiper-pagination',
                paginationClickable:false,
                spaceBetween: 30
            });
            $("#previewImg div[data-index]").removeClass("swiper-slide-active");
            $("#previewImg div[data-index='"+current_index+"']").addClass("swiper-slide-active");
        }
    }
});

//todo 评价图片预览退出
$("#previewImg").click(function(){
    $("#previewImg").hide();
});